/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package py.com.spadons.esmetil.controllers.jsf.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import py.com.spadons.esmetil.entities.Estacion;
import py.com.spadons.esmetil.utils.Anho;

/**
 *
 * @author spadons
 */

@FacesConverter(forClass = Anho.class)
public class AnhoConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
                return null;
            }
        
        return new Anho(Integer.parseInt(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) {
                return null;
            }
            if (value instanceof Anho) {
                Anho o = (Anho) value;
                return o.toString();
            } else {
                throw new IllegalArgumentException("object " + value + " is of type " + value.getClass().getName() + "; expected type: " + Anho.class.getName());
            }
    }
    
    
}
